package org.jeecg.modules.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.jeecg.modules.demo.interceptor.JwtTokenUserInterceptor;

@Configuration
@ComponentScan(basePackages = "org.jeecg.modules.demo")
public class WebMvcConfig implements WebMvcConfigurer {


    @Bean
    public JwtTokenUserInterceptor jwtTokenUserInterceptor() {
        return new JwtTokenUserInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenUserInterceptor())
                .addPathPatterns("/drf/**")  // 拦截所有以/drf/开头的请求
                .excludePathPatterns("/drf/Users/login")  // 排除登录接口
                .excludePathPatterns("/drf/Users/captcha") // 排除验证码接口
                .excludePathPatterns("/drf/Users/login/**")  // 排除登录接口的子路径
                .excludePathPatterns("/drf/Users/captcha/**") // 排除验证码接口的子路径
                .excludePathPatterns("/chat"); // 排除LangChain4j聊天接口
        
        // 如果有管理员相关接口，也需要配置相应的拦截规则
        // registry.addInterceptor(jwtTokenAdminInterceptor())
        //        .addPathPatterns("/admin/**");
    }
}